

import math
import normdist



class TheoPricer:



    @staticmethod
    def BlsPrice( S, X, RF, T,SIGMA,optionType="call", YIELD=0 ):
        #S = stock price
        #X = exercise price
        #RF = risk-free rate
        #T = time to expiration
        #SIGMA = volatility
        #YIELD = dividend yield
        #optionType--call, put

        d1=(math.log(S * math.exp(-YIELD * T) / X) + (RF + SIGMA*SIGMA / 2) * T) / (SIGMA * math.sqrt(T))
        d2 = d1 - SIGMA * math.sqrt(T)


        Nd1=normdist.phi(d1)
        Nd2=normdist.phi(d2)

        if optionType=="call":
            BSP = S * math.exp(-YIELD * T) * Nd1 - X * math.exp(-RF * T) * Nd2
        else:
            BSP = X * math.exp(-RF * T) * (1 - Nd2) - S * math.exp(-YIELD * T) * (1 - Nd1)

        return BSP;


